import {checkLogin} from './auth.js'
new Vue({
  el: '#app',
  data: {
    username: '',
    password: '',
    IS_LOGIN_USERNAME: null
  },
  async created() {
    this.IS_LOGIN_USERNAME = await checkLogin()
    if (this.IS_LOGIN_USERNAME) {
      location.href = '/'
    }
  },
  methods: {
    async login() {
      console.log('登录执行了', this.username, this.password)
      const res = await request.post('/user/login',{
        username: this.username,
        password: this.password
      })
      const token = res.data.token
      localStorage.setItem('token', token)
      this.$message.success('登录成功,正在跳转....')
      setTimeout(() => {
        location.href = '/'
      }, 1500)
    }
  }
})